package com.cndw.kungfu.model.task;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cndw.kungfu.config.ConstantsConfig;
import com.cndw.kungfu.domain.GoodsMode;
import com.cndw.kungfu.ext.XmlProcesser;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.vo.goodsvo.GoodsVO;

/**
 * 声望奖励的物品
 * 
 * @author fantadust [9677889@qq.com]
 * @date 2011-9-23 上午9:54:58
 */
public class PrestigeGoods {
	/**
	 * 编号
	 */
	private int id;
	/**
	 * 声望等级
	 */
	private int level;
	/**
	 * 所属城市
	 */
	private int sceneId;
	/**
	 * 物品id
	 */
	private int goodsId;
	/**
	 * 需要绑定金币
	 */
	private int goldTicke;

	private GoodsVO goodsVO;

	private static final Map<Integer, PrestigeGoods> dataMap = new HashMap<Integer, PrestigeGoods>();
	private static final Map<Integer, List<PrestigeGoods>> sceneDataMap = new HashMap<Integer, List<PrestigeGoods>>();

	public PrestigeGoods() {

	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public int getSceneId() {
		return sceneId;
	}

	public void setSceneId(int sceneId) {
		this.sceneId = sceneId;
	}

	public int getGoodsId() {
		return goodsId;
	}

	public void setGoodsId(int goodsId) {
		this.goodsId = goodsId;
	}

	public int getGoldTicke() {
		return goldTicke;
	}

	public void setGoldTicke(int goldTicke) {
		this.goldTicke = goldTicke;
	}

	public GoodsVO getGoodsVO() {
		return goodsVO;
	}

	public void setGoodsVO(GoodsVO goodsVO) {
		this.goodsVO = goodsVO;
	}

	static {
		reload();
	}

	public static synchronized void reload() {
		String fileName = ConstantsConfig.getLocaleResource() + "prestigeGoods.xml";
		List<PrestigeGoods> dataList = XmlProcesser.processXml(PrestigeGoods.class, fileName);
		if (dataList != null && dataList.size() > 0) {
			for (PrestigeGoods e : dataList) {
				GoodsMode goodsMode = Context.getGoodsServer().getModeById(e.getGoodsId());
				if (goodsMode == null) {
					continue;
				}
				e.setGoodsVO(goodsMode.toGoodsVO());
				if (sceneDataMap.containsKey(e.getSceneId()) == false) {
					sceneDataMap.put(e.getSceneId(), new ArrayList<PrestigeGoods>());
				}
				sceneDataMap.get(e.getSceneId()).add(e);
				dataMap.put(e.getId(), e);
			}
		}
	}

	public static Collection<PrestigeGoods> getPrestigeGoods() {
		return dataMap.values();
	}

	public static PrestigeGoods getOnePrestigeGoods(int id) {
		return dataMap.get(id);
	}

	public static Collection<PrestigeGoods> getListBySceneId(int sceneId) {
		return sceneDataMap.get(sceneId);
	}

}
